% TEST_ID: LANG-EXPAND-0017
% CATEGORY: language/array-ops/slice
% 测试 double 数组的索引行为

function test_double_slice
    B = reshape(1:24, 6, 4);
    assert(isequal(B(:, 1), [1; 2; 3; 4; 5; 6]))
    assert(isequal(B(:, 2), [7; 8; 9; 10; 11; 12]))
    assert(isequal(B(:, 3), [13; 14; 15; 16; 17; 18]))
    assert(isequal(B(:, 4), [19; 20; 21; 22; 23; 24]))

    B = reshape(B, 3, 2, 4);
    assert(isequal(B(1, :), [1 4 7 10 13 16 19 22]))
    assert(isequal(B(2, :), [2 5 8 11 14 17 20 23]))
    assert(isequal(B(3, :), [3 6 9 12 15 18 21 24]))

    B = B + B * i;
    assert(isequal(B(1, :), [1 + 1i 4 + 4i 7 + 7i 10 + 10i 13 + 13i 16 + 16i 19 + 19i 22 + 22i]))
    assert(isequal(B(2, :), [2 + 2i 5 + 5i 8 + 8i 11 + 11i 14 + 14i 17 + 17i 20 + 20i 23 + 23i]))
    assert(isequal(B(3, :), [3 + 3i 6 + 6i 9 + 9i 12 + 12i 15 + 15i 18 + 18i 21 + 21i 24 + 24i]))

    x = [1; 0; 0; 1; 0; 1; 0; 0; 0; 1; 1];
    assert(all(x(2:end) == [0; 0; 1; 0; 1; 0; 0; 0; 1; 1]));

    x = [1 0 0 1 0; 1 0 0 0 1];
    assert(all(x(:) == [1; 1; 0; 0; 0; 0; 1; 0; 0; 1]));

    B = reshape(1:24, 6, 4);
    B = B + B * i;
    assert(isequal(B(:, 1), [1 + 1i; 2 + 2i; 3 + 3i; 4 + 4i; 5 + 5i; 6 + 6i]))
    assert(isequal(B(:, 2), [7 + 7i; 8 + 8i; 9 + 9i; 10 + 10i; 11 + 11i; 12 + 12i]))
    assert(isequal(B(:, 3), [13 + 13i; 14 + 14i; 15 + 15i; 16 + 16i; 17 + 17i; 18 + 18i]))

    B = reshape(B, 2, 3, 4);
    assert(isequal(B(:, 5), [9 + 9i; 10 + 10i]));
    assert(isequal(B(:, 6), [11 + 11i; 12 + 12i]));

    B = [1 2 3 4];
    assert(isequal(B(:), [1;2;3;4]))
    assert(isequal(B([1;2]), [1 2]))
    assert(isequal(B([3 4]), [3 4]))

    B = [1 2; 3 4];
    assert(isequal(B(:), [1;3;2;4]))
    assert(isequal(B([1;2]), [1;3]))
    assert(isequal(B([3 4]), [2 4]))

    a = [1 2 3];
    error_happened = false;
    try
        b = a(1.5);
    catch
        error_happened = true;
    end
    assert(error_happened);

end